package com.cyj.dream.admin.persistence.manager.systems.config;

import com.alibaba.fastjson.JSONObject;
import com.cyj.dream.admin.model.system.config.SendMessage;
import com.cyj.dream.admin.persistence.service.ITbSendMessageService;
import com.cyj.dream.core.constant.pagemodel.Response;
import com.cyj.dream.core.constant.pagemodel.ResponseUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @Description: 阿里云短信实体管理器
 * @BelongsProject: dream-DreamChardonnay
 * @BelongsPackage: com.dream.DreamChardonnay.persistence.manager.systems.config
 * @Author: ChenYongJia
 * @CreateTime: 2021-05-19 10:31
 * @Email: chen87647213@163.com
 * @Version: 1.0
 */
@Slf4j
@Component
public class SendMessageManager {

    @Autowired
    private ITbSendMessageService iTbSendMessageService;

    /**
     * 添加阿里云短信模板信息
     *
     * @param sendMessage
     * @return com.dream.DreamChardonnay.constant.model.Response
     * @date 2021/5/19 10:35
     * @author ChenYongJia
     * @version 1.0
     */
    public Response addSendMessage(SendMessage sendMessage) {
        log.info("进入 SendMessageManager 添加阿里云短信模板信息方法，参数为：{}", JSONObject.toJSONString(sendMessage));
        sendMessage.setCreateTime(LocalDateTime.now());
        return iTbSendMessageService.save(sendMessage) ? ResponseUtil.success() : ResponseUtil.error();
    }

    /**
     * 修改阿里云短信模板信息
     *
     * @param sendMessage
     * @return com.dream.DreamChardonnay.constant.model.Response
     * @date 2021-5-19 10:44:07
     * @author ChenYongJia
     * @version 1.0
     */
    public Response updateSendMessage(SendMessage sendMessage) {
        log.info("进入 SendMessageManager 修改阿里云短信模板信息方法，参数为：{}", JSONObject.toJSONString(sendMessage));
        sendMessage.setUpdateTime(LocalDateTime.now());
        return iTbSendMessageService.updateById(sendMessage) ? ResponseUtil.success() : ResponseUtil.error();
    }

    /**
     * 删除阿里云短信模板信息
     *
     * @param sendMessage
     * @return com.dream.DreamChardonnay.constant.model.Response
     * @date 2021-5-19 10:46:21
     * @author ChenYongJia
     * @version 1.0
     */
    public Response deleteSendMessage(SendMessage sendMessage) {
        log.info("进入 SendMessageManager 删除阿里云短信模板信息方法，参数为：{}", JSONObject.toJSONString(sendMessage));
        return iTbSendMessageService.removeById(sendMessage) ? ResponseUtil.success() : ResponseUtil.error();
    }

}
